home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / kuaqe.zip / AEAPONS.QC next >
Text File  |  1996-09-29  |  36KB  |  1,662 lines

  1. /*
  2.  
  3. Modified Weapons.QC for cool stuff by Eli
  4.  
  5. */
  6.  
  7. float FLASHLIGHT_ON = 1;
  8. float LASER_ON = 2;
  9. float CHASECAM_ON = 4;
  10. float FOOTSTEPS_ON = 8;
  11. float SVC_SETVIEWPORT    = 5;
  12. float SVC_SETVIEWANGLES    = 10;
  13.  
  14. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  15. void () player_run;
  16. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  17. void(vector org, vector vel, float damage) SpawnBlood;
  18. void() SuperDamageSound;
  19. void (entity FlashlightOwner) FlashlightToggle;
  20. void () FlashlightTrack;
  21. void (entity LaserOwner) LaserToggle;
  22. void () LaserTrack;
  23. void () ChasecamToggle;
  24. void () ChasecamTrack;
  25. void (float opt) ChasecamRemove;
  26. void () ChasecamRestart;
  27. void (entity ChasecamOwner) ChasecamStart;
  28. void () EntityRemover;
  29. void () FlareTouch;
  30. void () FlareFire;
  31. void () FootstepsToggle;
  32.  
  33. // called by worldspawn
  34. void() W_Precache =
  35. {
  36.     precache_model ("progs/laser.mdl"); // Enforcer laser for flare
  37.     precache_sound ("misc/power.wav");  // new rocket explosion
  38.         precache_sound ("player/step.wav"); // Footsteps
  39.  
  40.     precache_sound ("weapons/r_exp3.wav");  // new rocket explosion
  41.     precache_sound ("weapons/rocket1i.wav");        // spike gun
  42.     precache_sound ("weapons/sgun1.wav");
  43.     precache_sound ("weapons/guncock.wav"); // player shotgun
  44.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  45.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  46.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  47.     precache_sound ("weapons/spike2.wav");  // super spikes
  48.     precache_sound ("weapons/tink1.wav");   // spikes tink (used in c code)
  49.     precache_sound ("weapons/grenade.wav"); // grenade launcher
  50.     precache_sound ("weapons/bounce.wav");          // grenade bounce
  51.     precache_sound ("weapons/shotgn2.wav"); // super shotgun
  52. };
  53.  
  54. float() crandom =
  55. {
  56.     return 2*(random() - 0.5);
  57. };
  58.  
  59. /*
  60. ================
  61. W_FireAxe
  62. ================
  63. */
  64. void() W_FireAxe =
  65. {
  66.     local   vector  source;
  67.     local   vector  org;
  68.  
  69.     source = self.origin + '0 0 16';
  70.     traceline (source, source + v_forward*64, FALSE, self);
  71.     if (trace_fraction == 1.0)
  72.         return;
  73.     
  74.     org = trace_endpos - v_forward*4;
  75.  
  76.     if (trace_ent.takedamage)
  77.     {
  78.         trace_ent.axhitme = 1;
  79.         SpawnBlood (org, '0 0 0', 20);
  80.         T_Damage (trace_ent, self, self, 20);
  81.     }
  82.     else
  83.     {       // hit wall
  84.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  85.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  86.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  87.         WriteCoord (MSG_BROADCAST, org_x);
  88.         WriteCoord (MSG_BROADCAST, org_y);
  89.         WriteCoord (MSG_BROADCAST, org_z);
  90.     }
  91. };
  92.  
  93.  
  94. //============================================================================
  95.  
  96.  
  97. vector() wall_velocity =
  98. {
  99.     local vector    vel;
  100.     
  101.     vel = normalize (self.velocity);
  102.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  103.     vel = vel + 2*trace_plane_normal;
  104.     vel = vel * 200;
  105.     
  106.     return vel;
  107. };
  108.  
  109.  
  110. /*
  111. ================
  112. SpawnMeatSpray
  113. ================
  114. */
  115. void(vector org, vector vel) SpawnMeatSpray =
  116. {
  117.     local   entity missile, mpuff;
  118.     local   vector  org;
  119.  
  120.     missile = spawn ();
  121.     missile.owner = self;
  122.     missile.movetype = MOVETYPE_BOUNCE;
  123.     missile.solid = SOLID_NOT;
  124.  
  125.     makevectors (self.angles);
  126.  
  127.     missile.velocity = vel;
  128.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  129.  
  130.     missile.avelocity = '3000 1000 2000';
  131.     
  132. // set missile duration
  133.     missile.nextthink = time + 1;
  134.     missile.think = SUB_Remove;
  135.  
  136.     setmodel (missile, "progs/zom_gib.mdl");
  137.     setsize (missile, '0 0 0', '0 0 0');            
  138.     setorigin (missile, org);
  139. };
  140.  
  141. /*
  142. ================
  143. SpawnBlood
  144. ================
  145. */
  146. void(vector org, vector vel, float damage) SpawnBlood =
  147. {
  148.     particle (org, vel*0.1, 73, damage*2);
  149. };
  150.  
  151. /*
  152. ================
  153. spawn_touchblood
  154. ================
  155. */
  156. void(float damage) spawn_touchblood =
  157. {
  158.     local vector    vel;
  159.  
  160.     vel = wall_velocity () * 0.2;
  161.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  162. };
  163.  
  164.  
  165. /*
  166. ================
  167. SpawnChunk
  168. ================
  169. */
  170. void(vector org, vector vel) SpawnChunk =
  171. {
  172.     particle (org, vel*0.02, 0, 10);
  173. };
  174.  
  175. /*
  176. ==============================================================================
  177.  
  178. MULTI-DAMAGE
  179.  
  180. Collects multiple small damages into a single damage
  181.  
  182. ==============================================================================
  183. */
  184.  
  185. entity  multi_ent;
  186. float   multi_damage;
  187.  
  188. void() ClearMultiDamage =
  189. {
  190.     multi_ent = world;
  191.     multi_damage = 0;
  192. };
  193.  
  194. void() ApplyMultiDamage =
  195. {
  196.     if (!multi_ent)
  197.         return;
  198.     T_Damage (multi_ent, self, self, multi_damage);
  199. };
  200.  
  201. void(entity hit, float damage) AddMultiDamage =
  202. {
  203.     if (!hit)
  204.         return;
  205.     
  206.     if (hit != multi_ent)
  207.     {
  208.         ApplyMultiDamage ();
  209.         multi_damage = damage;
  210.         multi_ent = hit;
  211.     }
  212.     else
  213.         multi_damage = multi_damage + damage;
  214. };
  215.  
  216. /*
  217. ==============================================================================
  218.  
  219. BULLETS
  220.  
  221. ==============================================================================
  222. */
  223.  
  224. /*
  225. ================
  226. TraceAttack
  227. ================
  228. */
  229. void(float damage, vector dir) TraceAttack =
  230. {
  231.     local   vector  vel, org;
  232.     
  233.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  234.     vel = vel + 2*trace_plane_normal;
  235.     vel = vel * 200;
  236.  
  237.     org = trace_endpos - dir*4;
  238.  
  239.     if (trace_ent.takedamage)
  240.     {
  241.         SpawnBlood (org, vel*0.2, damage);
  242.         AddMultiDamage (trace_ent, damage);
  243.     }
  244.     else
  245.     {
  246.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  247.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  248.         WriteCoord (MSG_BROADCAST, org_x);
  249.         WriteCoord (MSG_BROADCAST, org_y);
  250.         WriteCoord (MSG_BROADCAST, org_z);
  251.     }
  252. };
  253.  
  254. /*
  255. ================
  256. FireBullets
  257.  
  258. Used by shotgun, super shotgun, and enemy soldier firing
  259. Go to the trouble of combining multiple pellets into a single damage call.
  260. ================
  261. */
  262. void(float shotcount, vector dir, vector spread) FireBullets =
  263. {
  264.     local   vector direction;
  265.     local   vector  src;
  266.     
  267.     makevectors(self.v_angle);
  268.  
  269.     src = self.origin + v_forward*10;
  270.     src_z = self.absmin_z + self.size_z * 0.7;
  271.  
  272.     ClearMultiDamage ();
  273.     while (shotcount > 0)
  274.     {
  275.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  276.  
  277.         traceline (src, src + direction*2048, FALSE, self);
  278.         if (trace_fraction != 1.0)
  279.             TraceAttack (4, direction);
  280.  
  281.         shotcount = shotcount - 1;
  282.     }
  283.     ApplyMultiDamage ();
  284. };
  285.  
  286. /*
  287. ================
  288. W_FireShotgun
  289. ================
  290. */
  291. void() W_FireShotgun =
  292. {
  293.     local vector dir;
  294.  
  295.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); 
  296.  
  297.     self.punchangle_x = -2;
  298.     
  299.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  300.     dir = aim (self, 100000);
  301.     FireBullets (6, dir, '0.04 0.04 0');
  302. };
  303.  
  304.  
  305. /*
  306. ================
  307. W_FireSuperShotgun
  308. ================
  309. */
  310. void() W_FireSuperShotgun =
  311. {
  312.     local vector dir;
  313.  
  314.     if (self.currentammo == 1)
  315.     {
  316.         W_FireShotgun ();
  317.         return;
  318.     }
  319.         
  320.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); 
  321.  
  322.     self.punchangle_x = -4;
  323.     
  324.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  325.     dir = aim (self, 100000);
  326.     FireBullets (14, dir, '0.14 0.08 0');
  327. };
  328.  
  329.  
  330. /*
  331. ==============================================================================
  332.  
  333. ROCKETS
  334.  
  335. ==============================================================================
  336. */
  337.  
  338. void()  s_explode1      =       [0,             s_explode2] {};
  339. void()  s_explode2      =       [1,             s_explode3] {};
  340. void()  s_explode3      =       [2,             s_explode4] {};
  341. void()  s_explode4      =       [3,             s_explode5] {};
  342. void()  s_explode5      =       [4,             s_explode6] {};
  343. void()  s_explode6      =       [5,             SUB_Remove] {};
  344.  
  345. void() BecomeExplosion =
  346. {
  347.     self.movetype = MOVETYPE_NONE;
  348.     self.velocity = '0 0 0';
  349.     self.touch = SUB_Null;
  350.     setmodel (self, "progs/s_explod.spr");
  351.     self.solid = SOLID_NOT;
  352.     s_explode1 ();
  353. };
  354.  
  355. void() T_MissileTouch =
  356. {
  357.     local float     damg;
  358.  
  359.     if (other == self.owner)
  360.         return;         // don't explode on owner
  361.  
  362.     if (pointcontents(self.origin) == CONTENT_SKY)
  363.     {
  364.         remove(self);
  365.         return;
  366.     }
  367.  
  368.     damg = 100 + random()*20;
  369.     
  370.     if (other.health)
  371.     {
  372.         if (other.classname == "monster_shambler")
  373.             damg = damg * 0.5;      // mostly immune
  374.         T_Damage (other, self, self.owner, damg );
  375.     }
  376.  
  377.     // don't do radius damage to the other, because all the damage
  378.     // was done in the impact
  379.     T_RadiusDamage (self, self.owner, 120, other);
  380.  
  381. //      sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  382.     self.origin = self.origin - 8*normalize(self.velocity);
  383.  
  384.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  385.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  386.     WriteCoord (MSG_BROADCAST, self.origin_x);
  387.     WriteCoord (MSG_BROADCAST, self.origin_y);
  388.     WriteCoord (MSG_BROADCAST, self.origin_z);
  389.  
  390.     BecomeExplosion ();
  391. };
  392.  
  393.  
  394.  
  395. /*
  396. ================
  397. W_FireRocket
  398. ================
  399. */
  400. void() W_FireRocket =
  401. {
  402.     local   entity missile, mpuff;
  403.     
  404.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  405.     
  406.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  407.  
  408.     self.punchangle_x = -2;
  409.  
  410.     missile = spawn ();
  411.     missile.owner = self;
  412.     missile.movetype = MOVETYPE_FLYMISSILE;
  413.     missile.solid = SOLID_BBOX;
  414.         
  415. // set missile speed    
  416.  
  417.     makevectors (self.v_angle);
  418.     missile.velocity = aim(self, 1000);
  419.     missile.velocity = missile.velocity * 1000;
  420.     missile.angles = vectoangles(missile.velocity);
  421.     
  422.     missile.touch = T_MissileTouch;
  423.     
  424. // set missile duration
  425.     missile.nextthink = time + 5;
  426.     missile.think = SUB_Remove;
  427.  
  428.     setmodel (missile, "progs/missile.mdl");
  429.     setsize (missile, '0 0 0', '0 0 0');            
  430.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  431. };
  432.  
  433. /*
  434. ===============================================================================
  435.  
  436. LIGHTNING
  437.  
  438. ===============================================================================
  439. */
  440.  
  441. /*
  442. =================
  443. LightningDamage
  444. =================
  445. */
  446. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  447. {
  448.     local entity            e1, e2;
  449.     local vector            f;
  450.     
  451.     f = p2 - p1;
  452.     normalize (f);
  453.     f_x = 0 - f_y;
  454.     f_y = f_x;
  455.     f_z = 0;
  456.     f = f*16;
  457.  
  458.     e1 = e2 = world;
  459.  
  460.     traceline (p1, p2, FALSE, self);
  461.     if (trace_ent.takedamage)
  462.     {
  463.         particle (trace_endpos, '0 0 100', 225, damage*4);
  464.         T_Damage (trace_ent, from, from, damage);
  465.         if (self.classname == "player")
  466.         {
  467.             if (other.classname == "player")
  468.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  469.         }
  470.     }
  471.     e1 = trace_ent;
  472.  
  473.     traceline (p1 + f, p2 + f, FALSE, self);
  474.     if (trace_ent != e1 && trace_ent.takedamage)
  475.     {
  476.         particle (trace_endpos, '0 0 100', 225, damage*4);
  477.         T_Damage (trace_ent, from, from, damage);
  478.     }
  479.     e2 = trace_ent;
  480.  
  481.     traceline (p1 - f, p2 - f, FALSE, self);
  482.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  483.     {
  484.         particle (trace_endpos, '0 0 100', 225, damage*4);
  485.         T_Damage (trace_ent, from, from, damage);
  486.     }
  487. };
  488.  
  489.  
  490. void() W_FireLightning =
  491. {
  492.     local   vector          org;
  493.  
  494.     if (self.ammo_cells < 1)
  495.     {
  496.         self.weapon = W_BestWeapon ();
  497.         W_SetCurrentAmmo ();
  498.         return;
  499.     }
  500.  
  501. // explode if under water
  502.     if (self.waterlevel > 1)
  503.     {
  504.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  505.         self.ammo_cells = 0;
  506.         W_SetCurrentAmmo ();
  507.         return;
  508.     }
  509.  
  510.     if (self.t_width < time)
  511.     {
  512.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  513.         self.t_width = time + 0.6;
  514.     }
  515.     self.punchangle_x = -2;
  516.  
  517.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  518.  
  519.     org = self.origin + '0 0 16';
  520.     
  521.     traceline (org, org + v_forward*600, TRUE, self);
  522.  
  523.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  524.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  525.     WriteEntity (MSG_BROADCAST, self);
  526.     WriteCoord (MSG_BROADCAST, org_x);
  527.     WriteCoord (MSG_BROADCAST, org_y);
  528.     WriteCoord (MSG_BROADCAST, org_z);
  529.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  530.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  531.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  532.  
  533.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  534. };
  535.  
  536.  
  537. //=============================================================================
  538.  
  539.  
  540. void() GrenadeExplode =
  541. {
  542.     T_RadiusDamage (self, self.owner, 120, world);
  543.  
  544.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  545.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  546.     WriteCoord (MSG_BROADCAST, self.origin_x);
  547.     WriteCoord (MSG_BROADCAST, self.origin_y);
  548.     WriteCoord (MSG_BROADCAST, self.origin_z);
  549.  
  550.     BecomeExplosion ();
  551. };
  552.  
  553. void() GrenadeTouch =
  554. {
  555.     if (other == self.owner)
  556.         return;         // don't explode on owner
  557.     if (other.takedamage == DAMAGE_AIM)
  558.     {
  559.         GrenadeExplode();
  560.         return;
  561.     }
  562.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  563.     if (self.velocity == '0 0 0')
  564.         self.avelocity = '0 0 0';
  565. };
  566.  
  567. /*
  568. ================
  569. W_FireGrenade
  570. ================
  571. */
  572. void() W_FireGrenade =
  573. {
  574.     local   entity missile, mpuff;
  575.     
  576.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  577.     
  578.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  579.  
  580.     self.punchangle_x = -2;
  581.  
  582.     missile = spawn ();
  583.     missile.owner = self;
  584.     missile.movetype = MOVETYPE_BOUNCE;
  585.     missile.solid = SOLID_BBOX;
  586.     missile.classname = "grenade";
  587.         
  588. // set missile speed    
  589.  
  590.     makevectors (self.v_angle);
  591.  
  592.     if (self.v_angle_x)
  593.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  594.     else
  595.     {
  596.         missile.velocity = aim(self, 10000);
  597.         missile.velocity = missile.velocity * 600;
  598.         missile.velocity_z = 200;
  599.     }
  600.  
  601.     missile.avelocity = '300 300 300';
  602.  
  603.     missile.angles = vectoangles(missile.velocity);
  604.     
  605.     missile.touch = GrenadeTouch;
  606.     
  607. // set missile duration
  608.     missile.nextthink = time + 2.5;
  609.     missile.think = GrenadeExplode;
  610.  
  611.     setmodel (missile, "progs/grenade.mdl");
  612.     setsize (missile, '0 0 0', '0 0 0');            
  613.     setorigin (missile, self.origin);
  614. };
  615.  
  616.  
  617. //=============================================================================
  618.  
  619. void() spike_touch;
  620. void() superspike_touch;
  621.  
  622. /*
  623. ===============
  624. launch_spike
  625.  
  626. Used for both the player and the ogre
  627. ===============
  628. */
  629. void(vector org, vector dir) launch_spike =
  630. {
  631.     newmis = spawn ();
  632.     newmis.owner = self;
  633.     newmis.movetype = MOVETYPE_FLYMISSILE;
  634.     newmis.solid = SOLID_BBOX;
  635.  
  636.     newmis.angles = vectoangles(dir);
  637.     
  638.     newmis.touch = spike_touch;
  639.     newmis.classname = "spike";
  640.     newmis.think = SUB_Remove;
  641.     newmis.nextthink = time + 6;
  642.     setmodel (newmis, "progs/spike.mdl");
  643.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  644.     setorigin (newmis, org);
  645.  
  646.     newmis.velocity = dir * 1000;
  647. };
  648.  
  649. void() W_FireSuperSpikes =
  650. {
  651.     local vector    dir;
  652.     local entity    old;
  653.     
  654.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  655.     self.attack_finished = time + 0.2;
  656.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  657.     dir = aim (self, 1000);
  658.     launch_spike (self.origin + '0 0 16', dir);
  659.     newmis.touch = superspike_touch;
  660.     setmodel (newmis, "progs/s_spike.mdl");
  661.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);               
  662.     self.punchangle_x = -2;
  663. };
  664.  
  665. void(float ox) W_FireSpikes =
  666. {
  667.     local vector    dir;
  668.     local entity    old;
  669.     
  670.     makevectors (self.v_angle);
  671.     
  672.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  673.     {
  674.         W_FireSuperSpikes ();
  675.         return;
  676.     }
  677.  
  678.     if (self.ammo_nails < 1)
  679.     {
  680.         self.weapon = W_BestWeapon ();
  681.         W_SetCurrentAmmo ();
  682.         return;
  683.     }
  684.  
  685.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  686.     self.attack_finished = time + 0.2;
  687.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  688.     dir = aim (self, 1000);
  689.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  690.  
  691.     self.punchangle_x = -2;
  692. };
  693.  
  694.  
  695.  
  696. .float hit_z;
  697. void() spike_touch =
  698. {
  699. local float rand;
  700.     if (other == self.owner)
  701.         return;
  702.  
  703.     if (other.solid == SOLID_TRIGGER)
  704.         return; // trigger field, do nothing
  705.  
  706.     if (pointcontents(self.origin) == CONTENT_SKY)
  707.     {
  708.         remove(self);
  709.         return;
  710.     }
  711.     
  712. // hit something that bleeds
  713.     if (other.takedamage)
  714.     {
  715.         spawn_touchblood (9);
  716.         T_Damage (other, self, self.owner, 9);
  717.     }
  718.     else
  719.     {
  720.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  721.         
  722.         if (self.classname == "wizspike")
  723.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  724.         else if (self.classname == "knightspike")
  725.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  726.         else
  727.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  728.         WriteCoord (MSG_BROADCAST, self.origin_x);
  729.         WriteCoord (MSG_BROADCAST, self.origin_y);
  730.         WriteCoord (MSG_BROADCAST, self.origin_z);
  731.     }
  732.  
  733.     remove(self);
  734.  
  735. };
  736.  
  737. void() superspike_touch =
  738. {
  739. local float rand;
  740.     if (other == self.owner)
  741.         return;
  742.  
  743.     if (other.solid == SOLID_TRIGGER)
  744.         return; // trigger field, do nothing
  745.  
  746.     if (pointcontents(self.origin) == CONTENT_SKY)
  747.     {
  748.         remove(self);
  749.         return;
  750.     }
  751.     
  752. // hit something that bleeds
  753.     if (other.takedamage)
  754.     {
  755.         spawn_touchblood (18);
  756.         T_Damage (other, self, self.owner, 18);
  757.     }
  758.     else
  759.     {
  760.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  761.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  762.         WriteCoord (MSG_BROADCAST, self.origin_x);
  763.         WriteCoord (MSG_BROADCAST, self.origin_y);
  764.         WriteCoord (MSG_BROADCAST, self.origin_z);
  765.     }
  766.  
  767.     remove(self);
  768.  
  769. };
  770.  
  771. /*
  772. ===============================================================================
  773.  
  774. PLAYER WEAPON USE
  775.  
  776. ===============================================================================
  777. */
  778.  
  779. void() W_SetCurrentAmmo =
  780. {
  781.     player_run ();          // get out of any weapon firing states
  782.  
  783.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  784.     
  785.     if (self.weapon == IT_AXE)
  786.     {
  787.         self.currentammo = 0;
  788.         self.weaponmodel = "progs/v_axe.mdl";
  789.         self.weaponframe = 0;
  790.     }
  791.     else if (self.weapon == IT_SHOTGUN)
  792.     {
  793.         self.currentammo = self.ammo_shells;
  794.         self.weaponmodel = "progs/v_shot.mdl";
  795.         self.weaponframe = 0;
  796.         self.items = self.items | IT_SHELLS;
  797.     }
  798.     else if (self.weapon == IT_SUPER_SHOTGUN)
  799.     {
  800.         self.currentammo = self.ammo_shells;
  801.         self.weaponmodel = "progs/v_shot2.mdl";
  802.         self.weaponframe = 0;
  803.         self.items = self.items | IT_SHELLS;
  804.     }
  805.     else if (self.weapon == IT_NAILGUN)
  806.     {
  807.         self.currentammo = self.ammo_nails;
  808.         self.weaponmodel = "progs/v_nail.mdl";
  809.         self.weaponframe = 0;
  810.         self.items = self.items | IT_NAILS;
  811.     }
  812.     else if (self.weapon == IT_SUPER_NAILGUN)
  813.     {
  814.         self.currentammo = self.ammo_nails;
  815.         self.weaponmodel = "progs/v_nail2.mdl";
  816.         self.weaponframe = 0;
  817.         self.items = self.items | IT_NAILS;
  818.     }
  819.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  820.     {
  821.         self.currentammo = self.ammo_rockets;
  822.         self.weaponmodel = "progs/v_rock.mdl";
  823.         self.weaponframe = 0;
  824.         self.items = self.items | IT_ROCKETS;
  825.     }
  826.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  827.     {
  828.         self.currentammo = self.ammo_rockets;
  829.         self.weaponmodel = "progs/v_rock2.mdl";
  830.         self.weaponframe = 0;
  831.         self.items = self.items | IT_ROCKETS;
  832.     }
  833.     else if (self.weapon == IT_LIGHTNING)
  834.     {
  835.         self.currentammo = self.ammo_cells;
  836.         self.weaponmodel = "progs/v_light.mdl";
  837.         self.weaponframe = 0;
  838.         self.items = self.items | IT_CELLS;
  839.     }
  840.     else
  841.     {
  842.         self.currentammo = 0;
  843.         self.weaponmodel = "";
  844.         self.weaponframe = 0;
  845.     }
  846. };
  847.  
  848. float() W_BestWeapon =
  849. {
  850.     local   float   it;
  851.     
  852.     it = self.items;
  853.  
  854.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  855.         return IT_LIGHTNING;
  856.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  857.         return IT_SUPER_NAILGUN;
  858.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  859.         return IT_SUPER_SHOTGUN;
  860.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  861.         return IT_NAILGUN;
  862.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  863.         return IT_SHOTGUN;
  864.         
  865. /*
  866.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  867.         return IT_ROCKET_LAUNCHER;
  868.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  869.         return IT_GRENADE_LAUNCHER;
  870.  
  871. */
  872.  
  873.     return IT_AXE;
  874. };
  875.  
  876. float() W_CheckNoAmmo =
  877. {
  878.     if (self.currentammo > 0)
  879.         return TRUE;
  880.  
  881.     if (self.weapon == IT_AXE)
  882.         return TRUE;
  883.     
  884.     self.weapon = W_BestWeapon ();
  885.  
  886.     W_SetCurrentAmmo ();
  887.     
  888. // drop the weapon down
  889.     return FALSE;
  890. };
  891.  
  892. /*
  893. ============
  894. W_Attack
  895.  
  896. An attack impulse can be triggered now
  897. ============
  898. */
  899. void()  player_axe1;
  900. void()  player_axeb1;
  901. void()  player_axec1;
  902. void()  player_axed1;
  903. void()  player_shot1;
  904. void()  player_nail1;
  905. void()  player_light1;
  906. void()  player_rocket1;
  907.  
  908. void() W_Attack =
  909. {
  910.     local   float   r;
  911.  
  912.     if (!W_CheckNoAmmo ())
  913.         return;
  914.  
  915.     makevectors     (self.v_angle);                 // calculate forward angle for velocity
  916.     self.show_hostile = time + 1;   // wake monsters up
  917.  
  918.     if (self.weapon == IT_AXE)
  919.     {
  920.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  921.         r = random();
  922.         if (r < 0.25)
  923.             player_axe1 ();
  924.         else if (r<0.5)
  925.             player_axeb1 ();
  926.         else if (r<0.75)
  927.             player_axec1 ();
  928.         else
  929.             player_axed1 ();
  930.         self.attack_finished = time + 0.5;
  931.     }
  932.     else if (self.weapon == IT_SHOTGUN)
  933.     {
  934.         player_shot1 ();
  935.         W_FireShotgun ();
  936.         self.attack_finished = time + 0.5;
  937.     }
  938.     else if (self.weapon == IT_SUPER_SHOTGUN)
  939.     {
  940.         player_shot1 ();
  941.         W_FireSuperShotgun ();
  942.         self.attack_finished = time + 0.7;
  943.     }
  944.     else if (self.weapon == IT_NAILGUN)
  945.     {
  946.         player_nail1 ();
  947.     }
  948.     else if (self.weapon == IT_SUPER_NAILGUN)
  949.     {
  950.         player_nail1 ();
  951.     }
  952.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  953.     {
  954.         player_rocket1();
  955.         W_FireGrenade();
  956.         self.attack_finished = time + 0.6;
  957.     }
  958.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  959.     {
  960.         player_rocket1();
  961.         W_FireRocket();
  962.         self.attack_finished = time + 0.8;
  963.     }
  964.     else if (self.weapon == IT_LIGHTNING)
  965.     {
  966.         player_light1();
  967.         self.attack_finished = time + 0.1;
  968.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  969.     }
  970. };
  971.  
  972. /*
  973. ============
  974. W_ChangeWeapon
  975.  
  976. ============
  977. */
  978. void() W_ChangeWeapon =
  979. {
  980.     local   float   it, am, fl;
  981.     
  982.     it = self.items;
  983.     am = 0;
  984.     
  985.     if (self.impulse == 1)
  986.     {
  987.         fl = IT_AXE;
  988.     }
  989.     else if (self.impulse == 2)
  990.     {
  991.         fl = IT_SHOTGUN;
  992.         if (self.ammo_shells < 1)
  993.             am = 1;
  994.     }
  995.     else if (self.impulse == 3)
  996.     {
  997.         fl = IT_SUPER_SHOTGUN;
  998.         if (self.ammo_shells < 2)
  999.             am = 1;
  1000.     }               
  1001.     else if (self.impulse == 4)
  1002.     {
  1003.         fl = IT_NAILGUN;
  1004.         if (self.ammo_nails < 1)
  1005.             am = 1;
  1006.     }
  1007.     else if (self.impulse == 5)
  1008.     {
  1009.         fl = IT_SUPER_NAILGUN;
  1010.         if (self.ammo_nails < 2)
  1011.             am = 1;
  1012.     }
  1013.     else if (self.impulse == 6)
  1014.     {
  1015.         fl = IT_GRENADE_LAUNCHER;
  1016.         if (self.ammo_rockets < 1)
  1017.             am = 1;
  1018.     }
  1019.     else if (self.impulse == 7)
  1020.     {
  1021.         fl = IT_ROCKET_LAUNCHER;
  1022.         if (self.ammo_rockets < 1)
  1023.             am = 1;
  1024.     }
  1025.     else if (self.impulse == 8)
  1026.     {
  1027.         fl = IT_LIGHTNING;
  1028.         if (self.ammo_cells < 1)
  1029.             am = 1;
  1030.     }
  1031.  
  1032.     self.impulse = 0;
  1033.     
  1034.     if (!(self.items & fl))
  1035.     {       // don't have the weapon or the ammo
  1036.         sprint (self, "no weapon.\n");
  1037.         return;
  1038.     }
  1039.     
  1040.     if (am)
  1041.     {       // don't have the ammo
  1042.         sprint (self, "not enough ammo.\n");
  1043.         return;
  1044.     }
  1045.  
  1046. //
  1047. // set weapon, set ammo
  1048. //
  1049.     self.weapon = fl;               
  1050.     W_SetCurrentAmmo ();
  1051. };
  1052.  
  1053. /*
  1054. ============
  1055. CheatCommand
  1056. ============
  1057. */
  1058. void() CheatCommand =
  1059. {
  1060.     self.ammo_rockets = 100;
  1061.     self.ammo_nails = 200;
  1062.     self.ammo_shells = 100;
  1063.     self.items = self.items | 
  1064.         IT_AXE |
  1065.         IT_SHOTGUN |
  1066.         IT_SUPER_SHOTGUN |
  1067.         IT_NAILGUN |
  1068.         IT_SUPER_NAILGUN |
  1069.         IT_GRENADE_LAUNCHER |
  1070.         IT_ROCKET_LAUNCHER |
  1071.         IT_KEY1 | IT_KEY2;
  1072.  
  1073.     self.ammo_cells = 200;
  1074.     self.items = self.items | IT_LIGHTNING;
  1075.  
  1076.     self.weapon = IT_ROCKET_LAUNCHER;
  1077.     self.impulse = 0;
  1078.     W_SetCurrentAmmo ();
  1079. };
  1080.  
  1081. /*
  1082. ============
  1083. CycleWeaponCommand
  1084.  
  1085. Go to the next weapon with ammo
  1086. ============
  1087. */
  1088. void() CycleWeaponCommand =
  1089. {
  1090.     local   float   it, am;
  1091.     
  1092.     it = self.items;
  1093.     self.impulse = 0;
  1094.     
  1095.     while (1)
  1096.     {
  1097.         am = 0;
  1098.  
  1099.         if (self.weapon == IT_LIGHTNING)
  1100.         {
  1101.             self.weapon = IT_AXE;
  1102.         }
  1103.         else if (self.weapon == IT_AXE)
  1104.         {
  1105.             self.weapon = IT_SHOTGUN;
  1106.             if (self.ammo_shells < 1)
  1107.                 am = 1;
  1108.         }
  1109.         else if (self.weapon == IT_SHOTGUN)
  1110.         {
  1111.             self.weapon = IT_SUPER_SHOTGUN;
  1112.             if (self.ammo_shells < 2)
  1113.                 am = 1;
  1114.         }               
  1115.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1116.         {
  1117.             self.weapon = IT_NAILGUN;
  1118.             if (self.ammo_nails < 1)
  1119.                 am = 1;
  1120.         }
  1121.         else if (self.weapon == IT_NAILGUN)
  1122.         {
  1123.             self.weapon = IT_SUPER_NAILGUN;
  1124.             if (self.ammo_nails < 2)
  1125.                 am = 1;
  1126.         }
  1127.         else if (self.weapon == IT_SUPER_NAILGUN)
  1128.         {
  1129.             self.weapon = IT_GRENADE_LAUNCHER;
  1130.             if (self.ammo_rockets < 1)
  1131.                 am = 1;
  1132.         }
  1133.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1134.         {
  1135.             self.weapon = IT_ROCKET_LAUNCHER;
  1136.             if (self.ammo_rockets < 1)
  1137.                 am = 1;
  1138.         }
  1139.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1140.         {
  1141.             self.weapon = IT_LIGHTNING;
  1142.             if (self.ammo_cells < 1)
  1143.                 am = 1;
  1144.         }
  1145.     
  1146.         if ( (self.items & self.weapon) && am == 0)
  1147.         {
  1148.             W_SetCurrentAmmo ();
  1149.             return;
  1150.         }
  1151.     }
  1152.  
  1153. };
  1154.  
  1155. /*
  1156. ============
  1157. ServerflagsCommand
  1158.  
  1159. Just for development
  1160. ============
  1161. */
  1162. void() ServerflagsCommand =
  1163. {
  1164.     serverflags = serverflags * 2 + 1;
  1165. };
  1166.  
  1167. void() QuadRemove =
  1168. {
  1169.         self.super_time = 0;
  1170.         self.super_damage_finished = 0;
  1171.         self.items = self.items - IT_QUAD;
  1172.         dprint ("quad cheat disabled\n");
  1173. };
  1174.  
  1175. void() QuadCheat =
  1176. {
  1177.     self.super_time = 1;
  1178.         self.super_damage_finished = time + 100000;
  1179.     self.items = self.items | IT_QUAD;
  1180.     dprint ("quad cheat\n");
  1181. };
  1182.  
  1183. /*
  1184. ============
  1185. ImpulseCommands
  1186.  
  1187. ============
  1188. */
  1189. void() ImpulseCommands =
  1190. {
  1191.     if (self.impulse >= 1 && self.impulse <= 8)
  1192.         W_ChangeWeapon ();
  1193.  
  1194.     if (self.impulse == 9)
  1195.         CheatCommand ();
  1196.     
  1197.     if (self.impulse == 10)
  1198.         CycleWeaponCommand ();
  1199.     if (self.impulse == 11)
  1200.         ServerflagsCommand ();
  1201.  
  1202.         if (self.impulse == 15)
  1203.                 FlareFire ();
  1204.  
  1205.         if (self.impulse == 16)
  1206.                 EntityRemover ();
  1207.  
  1208.         if (self.impulse == 254)
  1209.                 QuadRemove ();
  1210.         if (self.impulse == 255)
  1211.         QuadCheat ();
  1212.         
  1213.         if (self.impulse == 12)
  1214.                 FlashlightToggle (self);
  1215.  
  1216.         if (self.impulse == 13)
  1217.                 LaserToggle (self);
  1218.  
  1219.         if (self.impulse == 14)
  1220.                 ChasecamToggle ();
  1221.  
  1222.         if (self.impulse == 17)
  1223.                 FootstepsToggle ();
  1224.  
  1225.         self.impulse = 0;
  1226. };
  1227.  
  1228. /*
  1229. ============
  1230. W_WeaponFrame
  1231.  
  1232. Called every frame so impulse events can be handled as well as possible
  1233. ============
  1234. */
  1235. void() W_WeaponFrame =
  1236. {
  1237.     if (time < self.attack_finished)
  1238.         return;
  1239.  
  1240.     ImpulseCommands ();
  1241.     
  1242. // check for attack
  1243.     if (self.button0)
  1244.     {
  1245.         SuperDamageSound ();
  1246.         W_Attack ();
  1247.     }
  1248. };
  1249.  
  1250. /*
  1251. ========
  1252. SuperDamageSound
  1253.  
  1254. Plays sound if needed
  1255. ========
  1256. */
  1257. void() SuperDamageSound =
  1258. {
  1259.     if (self.super_damage_finished > time)
  1260.     {
  1261.         if (self.super_sound < time)
  1262.         {
  1263.             self.super_sound = time + 1;
  1264.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1265.         }
  1266.     }
  1267.     return;
  1268. };
  1269.  
  1270. /*
  1271. ======================
  1272. Flashlight Code by Eli
  1273. ======================
  1274. */
  1275.  
  1276. void() FlashlightTrack =
  1277. {
  1278.   local vector src,
  1279.                dir;
  1280.  
  1281.   if (!(self.owner.speed & FLASHLIGHT_ON))
  1282.   {
  1283.     remove(self);
  1284.     return;
  1285.   }
  1286.  
  1287.   makevectors (self.owner.v_angle);
  1288.   src = self.owner.origin + '0 0 16' + v_forward * 10;
  1289.   dir = aim(self.owner, 100000);
  1290.   traceline (src, src + dir * 2048, FALSE, self.owner);
  1291.   if (trace_fraction != 1.0)
  1292.     src = trace_endpos - dir*4;
  1293.   setorigin (self, src);
  1294.   self.nextthink = time + 0.1;
  1295. };
  1296.  
  1297. void(entity FlashlightOwner) FlashlightToggle =
  1298. {
  1299.   local entity Flashlight;
  1300.  
  1301.   if ((self.speed & FLASHLIGHT_ON))
  1302.     self.speed = self.speed - FLASHLIGHT_ON;
  1303.   else
  1304.   {
  1305.     self.speed = self.speed | FLASHLIGHT_ON;
  1306.     Flashlight = spawn();
  1307.     Flashlight.owner = FlashlightOwner;
  1308.     Flashlight.movetype = MOVETYPE_NONE;
  1309.     Flashlight.solid = SOLID_NOT;
  1310.     setmodel (Flashlight, "progs/null.spr");
  1311.     setsize (Flashlight, VEC_ORIGIN, VEC_ORIGIN);
  1312.     setorigin (Flashlight, self.owner.origin);
  1313.     Flashlight.nextthink = time + 0.1;
  1314.     Flashlight.think = FlashlightTrack;
  1315.     Flashlight.effects = EF_DIMLIGHT;
  1316.   }
  1317.  
  1318.   return;
  1319. };
  1320.  
  1321. /*
  1322. End Flashlight Code
  1323. */
  1324.  
  1325. /*
  1326. =============================
  1327. Laser Targeting System by Eli
  1328. =============================
  1329. */
  1330.  
  1331. void () LaserTrack =
  1332. {
  1333.   local vector src,
  1334.                dir;
  1335.  
  1336.   if (!(self.owner.speed & LASER_ON))
  1337.   {
  1338.     remove (self);
  1339.     return;
  1340.   }
  1341.  
  1342.   makevectors (self.owner.v_angle);
  1343.   src = self.owner.origin + '0 0 16' + v_forward * 10;
  1344.   dir = aim(self.owner, 100000);
  1345.   traceline (src, src + dir * 320, FALSE, self.owner);
  1346.   src = 0.1 * src + 0.9 * trace_endpos;
  1347.   setorigin (self, src);
  1348.   self.nextthink = time + 0.1;
  1349. };
  1350.  
  1351. void (entity LaserOwner) LaserToggle =
  1352. {
  1353.   local entity Laser;
  1354.  
  1355.   if ((self.speed & LASER_ON))
  1356.   {
  1357.     self.speed = self.speed - LASER_ON;
  1358.   }
  1359.   else
  1360.   {
  1361.   self.speed = self.speed | LASER_ON;
  1362.   Laser = spawn ();
  1363.   Laser.owner = LaserOwner;
  1364.   Laser.movetype = MOVETYPE_NONE;
  1365.   Laser.solid = SOLID_NOT;
  1366.   setmodel (Laser, "progs/s_bubble.spr");
  1367.   setsize (Laser, VEC_ORIGIN, VEC_ORIGIN);
  1368.   setorigin (Laser, self.owner.origin);
  1369.   Laser.nextthink = time + 0.1;
  1370.   Laser.think = LaserTrack;
  1371.   }
  1372.  
  1373.   return;
  1374. };
  1375.  
  1376. /*
  1377. End Laser Targeting Code
  1378. */
  1379.  
  1380. /*
  1381. ===============
  1382. ChaseCam by Eli
  1383. ===============
  1384. */
  1385.  
  1386. float ChasecamDistance = 72, ChasecamZ = 16;
  1387.  
  1388. // called either by player or chase cam entities (to restart)
  1389. void (entity ChasecamOwner) ChasecamStart =
  1390. {
  1391.   local entity Chasecam;
  1392.  
  1393.   ChasecamOwner.speed = ChasecamOwner.speed | CHASECAM_ON;
  1394.   cvar_set ("r_drawviewmodel", "0");
  1395.  
  1396.   Chasecam = spawn ();
  1397.  
  1398.   Chasecam.owner = ChasecamOwner;
  1399.   Chasecam.solid = SOLID_NOT;
  1400.   Chasecam.movetype = MOVETYPE_FLYMISSILE;
  1401.   Chasecam.angles = Chasecam.owner.angles;
  1402.   setmodel (Chasecam, "progs/null.spr");
  1403.   setsize (Chasecam, '0 0 0', '0 0 0');
  1404.   setorigin (Chasecam, Chasecam.owner.origin);
  1405.   Chasecam.classname = "Chasecam";
  1406.   Chasecam.nextthink = time + 0.1; 
  1407.   Chasecam.think = ChasecamTrack;
  1408.   msg_entity = Chasecam.owner; // target of message
  1409.   WriteByte (MSG_ONE, SVC_SETVIEWPORT);  
  1410.   WriteEntity (MSG_ONE, Chasecam); // view port
  1411.   Chasecam.ammo_shells = ChasecamDistance;
  1412. };
  1413.  
  1414. // secondary think function for cam entities
  1415. void () ChasecamRestart =
  1416. {
  1417.   self.nextthink = time + 0.1;
  1418.  
  1419.   if (self.owner.health <= 0)
  1420.   {
  1421.     remove (self);
  1422.     return;
  1423.   }
  1424.  
  1425.   if (self.owner.waterlevel)
  1426.     return;
  1427.  
  1428.   ChasecamStart (self.owner);
  1429.   remove (self);
  1430. };
  1431.  
  1432. // called only by chase cam entities.
  1433. // opt values:
  1434. // TRUE = remove completely
  1435. // FALSE = remove view but keep alive with ChasecamRestart();
  1436. void (float opt) ChasecamRemove =
  1437. {
  1438.   if ((self.owner.speed & CHASECAM_ON))
  1439.     self.owner.speed = self.owner.speed - CHASECAM_ON;
  1440.  
  1441.   setmodel (self, "");
  1442.   self.velocity = '0 0 0';
  1443.   cvar_set ("r_drawviewmodel", "1");
  1444.  
  1445.   msg_entity = self.owner;      // target of message
  1446.   WriteByte (MSG_ONE, SVC_SETVIEWPORT);  
  1447.   WriteEntity (MSG_ONE, self.owner);           // view port
  1448.     
  1449.   if (!opt)
  1450.   {
  1451.     self.nextthink = time + 0.1;
  1452.     self.think = ChasecamRestart;
  1453.   }
  1454.   else
  1455.     remove (self);
  1456. };
  1457.  
  1458.  
  1459. // main think function for cam entities
  1460. // self.ammo_shells = distance clipping
  1461. // self.ammo_nails = hang-up flag
  1462. void() ChasecamTrack =
  1463. {
  1464.   local vector spot2,
  1465.                dir;
  1466.   local float  dist,
  1467.                cap;
  1468.     
  1469.   self.nextthink = time + 0.1; 
  1470.  
  1471.   if (!(self.owner.speed & CHASECAM_ON))
  1472.   {
  1473.     ChasecamRemove (TRUE);
  1474.     return;
  1475.   }
  1476.  
  1477.   if ((self.owner.waterlevel) && (self.owner.health > 0))
  1478.   {
  1479.     ChasecamRemove (FALSE);
  1480.     return;
  1481.   }
  1482.     
  1483.   makevectors (self.owner.v_angle);
  1484.  
  1485.   spot2 = self.owner.origin - (v_forward * self.ammo_shells);
  1486.   spot2_z = spot2_z + ChasecamZ;
  1487.  
  1488.   traceline (self.owner.origin, spot2, TRUE, self.owner);
  1489.   self.ammo_shells = vlen (trace_endpos - self.owner.origin);
  1490.   spot2 = trace_endpos + (v_forward * 2);
  1491.  
  1492.   traceline (spot2, spot2 + '0 0 32', TRUE, self.owner );
  1493.   if (trace_fraction < 1 )
  1494.     spot2 = trace_endpos - '0 0 32';
  1495.  
  1496.   dir = normalize (spot2 - self.origin);
  1497.   dist = vlen (spot2 - self.origin);
  1498.  
  1499.   traceline (self.origin, spot2, TRUE, self.owner);
  1500.   if (trace_fraction == 1)
  1501.   {
  1502.     self.angles = self.owner.angles;
  1503.     cap = dist * 0.2;
  1504.  
  1505.     if (cap > 5.2)
  1506.       self.velocity = dir * dist * 5.2;
  1507.     else if (cap > 1)
  1508.       self.velocity = dir * dist * cap;
  1509.     else
  1510.       self.velocity = dir * dist;
  1511.  
  1512.     if ((vlen(self.owner.origin - self.origin)) < 30)
  1513.     {
  1514.       self.velocity = self.velocity * 2;
  1515.     }
  1516.   }
  1517.   else
  1518.     setorigin (self, spot2);
  1519.    
  1520.   self.ammo_shells = self.ammo_shells + 4;
  1521.  
  1522.   if (self.ammo_shells > ChasecamDistance)
  1523.     self.ammo_shells = ChasecamDistance;
  1524.  
  1525.   // respawn if missile ent. get's hung up
  1526.   if (self.oldorigin == self.origin)
  1527.   {
  1528.     if (dist > 30)
  1529.       self.ammo_nails = self.ammo_nails + 1;
  1530.   }
  1531.  
  1532.   if (self.ammo_nails > 3)
  1533.   {
  1534.     ChasecamStart (self.owner);
  1535.     remove (self);
  1536.     return;
  1537.   }
  1538.  
  1539.   self.oldorigin = self.origin;
  1540. };
  1541.  
  1542. void () ChasecamToggle =
  1543. {
  1544.   if ((self.speed & CHASECAM_ON))
  1545.   {
  1546.     cvar_set ("scr_ofsx", "-2");
  1547.     cvar_set ("scr_ofsy", "2");
  1548.     self.speed = self.speed - CHASECAM_ON;
  1549.   }
  1550.   else
  1551.   {
  1552.     cvar_set ("scr_ofsx", "0");
  1553.     cvar_set ("scr_ofxy", "0");
  1554.     ChasecamStart (self);
  1555.   }
  1556. };
  1557.  
  1558. /*
  1559. End Chasecam Code
  1560. */
  1561.  
  1562. /*
  1563. =====================
  1564. Entity Remover by Eli
  1565. =====================
  1566. */
  1567.  
  1568. void () EntityRemover =
  1569. {
  1570.   local vector src, dir;
  1571.     
  1572.   sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  1573.  
  1574.   makevectors (self.v_angle);
  1575.   self.attack_finished = time + 0.5;
  1576.   dir = aim (self, 100000);
  1577.   src = self.origin + '0 0 16' + v_forward * 10;
  1578.   traceline (src, src + dir * 2048, FALSE, self);
  1579.   if (trace_ent != world)
  1580.     remove (trace_ent);
  1581. };
  1582.  
  1583. /*
  1584. End Entity Remover Code
  1585. */
  1586.  
  1587. /*
  1588. ================
  1589. Flare Gun by Eli
  1590. ================
  1591. */
  1592.  
  1593. void () FlareFire =
  1594. {
  1595.   local entity Flare;
  1596.  
  1597.   makevectors (self.v_angle);
  1598.  
  1599.   sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  1600.   self.attack_finished = time + 0.5;
  1601.   self.punchangle_x = -2;
  1602.  
  1603.   Flare = spawn ();
  1604.   Flare.owner = self;
  1605.   Flare.movetype = MOVETYPE_FLYMISSILE;
  1606.   Flare.solid = SOLID_BBOX;
  1607.   Flare.velocity = aim (self, 1000);
  1608.   Flare.velocity = Flare.velocity * 1000;
  1609.   Flare.angles = vectoangles (Flare.velocity);
  1610.   Flare.touch = FlareTouch;
  1611.   Flare.classname = "Flare";
  1612.   Flare.think = SUB_Remove;
  1613.   Flare.nextthink = time + 7;
  1614.   setmodel (Flare, "progs/laser.mdl");
  1615.   setsize (Flare, VEC_ORIGIN, VEC_ORIGIN);               
  1616.   setorigin (Flare, self.origin + '0 0 16');
  1617.   Flare.effects = EF_DIMLIGHT;
  1618. };
  1619.  
  1620. void () FlareTouch =
  1621. {
  1622.   local float rand;
  1623.  
  1624.   if (other == self.owner)
  1625.     return;
  1626.  
  1627.   if (other.classname == "door" || other.classname == "plat")
  1628.   {
  1629.     remove (self);
  1630.     return;
  1631.   }
  1632.  
  1633.   if (other.solid == SOLID_TRIGGER)
  1634.     return;
  1635.  
  1636.   if (other.takedamage)
  1637.   {
  1638.     spawn_touchblood (2);
  1639.     T_Damage (other, self, self.owner, 1);
  1640.     remove (self);
  1641.     return;
  1642.   }
  1643.  
  1644.   self.movetype = MOVETYPE_NONE;
  1645.   self.solid = SOLID_NOT;
  1646.   self.origin = self.origin - self.velocity * 0.005;
  1647.   self.velocity = '0 0 0';
  1648.   self.touch = SUB_Null;
  1649. };
  1650.  
  1651. /*
  1652. End Flare Gun Code
  1653. */
  1654.  
  1655. void () FootstepsToggle =
  1656. {
  1657.   if ((self.speed & FOOTSTEPS_ON))
  1658.     self.speed = self.speed - FOOTSTEPS_ON;
  1659.   else
  1660.     self.speed = self.speed | FOOTSTEPS_ON;
  1661. };
  1662.